import http from '@/axios'
import {handleError} from "vue";
import {handleSuccess} from "@/api/index.js";


export const configAPI = {
    // 获取配置列表

    getConfigList() {
        return http.get('config/all')
            .then(res => handleSuccess(res, '获取配置列表成功'))
            .catch(error => handleError(error, '获取配置列表失败', '服务器异常'));
    },

    //刷新配置缓存
    refreshCache() {
        return http.post('config/refreshCache')
            .then(res => handleSuccess(res, '刷新配置缓存成功'))
            .catch(error => handleError(error, '刷新配置缓存失败', '服务器异常'));
    },

    //获取公共配置
    getCommonConfig() {
        return http.get('config/public')
            .then(res => handleSuccess(res, '获取公共配置成功'))
            .catch(error => handleError(error, '获取公共配置失败', '服务器异常'));
    },

    //更新配置
    updateConfig(id,configValue) {
         return http.put(`config/update?id=${id}&configValue=${configValue}`) 
            .then(res => handleSuccess(res, '更新配置成功'))
            .catch(error => handleError(error, '更新配置失败', '服务器异常'));
    },

    //配置历史记录查询
    getConfigHistory(configKey, operatorId, page, pageSize) {
        return http.get('config/history', {params: {configKey, operatorId, page, pageSize}})
            .then(res => handleSuccess(res, '获取配置历史记录成功'))
            .catch(error => handleError(error, '获取配置历史记录失败', '服务器异常'));
    },
       //获取配置详情
    getConfigDetail(id){
        return http.get('config/detail',{params:{id}})
            .then(res => handleSuccess(res, '获取配置详情成功'))
            .catch(error => handleError(error, '获取配置详情失败', '服务器异常'));
    },
    //模糊查询配置
    searchConfig(configKey){
        return http.get('config/search',{params:{configKey}})
            .then(res => handleSuccess(res, '查询配置成功'))
            .catch(error => handleError(error, '查询配置失败', '服务器异常'));
    }


}